﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Documents;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Media;

namespace CodeCounsel.SharePoint.RibbonDesigner.View.AttachedBehaviors
{
	public class DraggedAdorner : Adorner
	{
		private ContentPresenter contentPresenter;
		private double left;
		private double top;

		public DraggedAdorner(object dragDropData, DataTemplate dragDropTemplate, UIElement adornedElement)
			: base(adornedElement)
		{

			this.contentPresenter = new ContentPresenter();
			this.contentPresenter.Content = dragDropData;
			this.contentPresenter.ContentTemplate = dragDropTemplate;
			this.contentPresenter.Opacity = 0.7;

		}

		public void SetPosition(double left, double top)
		{
			this.left = left - 1;
			this.top = top + 13;
		}

		protected override Size MeasureOverride(Size constraint)
		{
			this.contentPresenter.Measure(constraint);
			return this.contentPresenter.DesiredSize;
		}

		protected override Size ArrangeOverride(Size finalSize)
		{
			this.contentPresenter.Arrange(new Rect(finalSize));
			return finalSize;
		}

		protected override Visual GetVisualChild(int index)
		{
			return this.contentPresenter;
		}

		protected override int VisualChildrenCount
		{
			get { return 1; }
		}

		public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
		{
			GeneralTransformGroup result = new GeneralTransformGroup();
			result.Children.Add(base.GetDesiredTransform(transform));
			result.Children.Add(new TranslateTransform(this.left, this.top));
			return result;
		}
	}
}
